/**
 * Created by hehe on 2015/7/21.
 */
var uuid = require('uuid'),
    mime = require('mime'),
    BizFactory = require('../biz'),
    BaseAction = require('./BaseAction').BaseAction;

exports.upload = function(req,res){
    var data = req.body,
        baseAction = new BaseAction();
        fileBiz = new BizFactory.FileBiz(),
        fileType = mime.extension(data.fileHeader),
        fileRename = uuid.v1()+'.'+fileType;

    data.fileRename = fileRename;
    if(data.parserType && data.fileHeader){
        fileBiz.execute(data)
            .then(function(result){
                res.send(baseAction.formattedResult(true,result));
            });
    }else{
        res.send(baseAction.formattedResult(false,'输入信息不完整'))
    }

}


exports.findFileListByStatus = function(req,res){
    var fileBiz = new BizFactory.FileBiz(),
        baseAction = new BaseAction(),
        params = req.query;
    if(!params.pageSize){
        params.pageSize = 100;
    }

    if(!params.startAt){
        params.startAt = 0;
    }

    fileBiz.findFileListByStatus(params).then(function(result){
        res.send(baseAction.formattedResult(true,result));
    }, function (err) {
        res.send(baseAction.formattedResult(true,result));
    });
}

